/**
 * 
 */
package gui;

import java.awt.Component;

import components.Ball;

/**
 * A runnable that animates a bouncing ball.
 */
public class BallRunnable implements Runnable
{
	private Ball ball;

	private Component component;

	public static final int STEPS = 1000;
	public static final int DELAY = 5;

	/**
	 * Constructs the runnable.
	 * 
	 * @aBall the ball to bounce
	 * @aPanel the component in which the ball bounces
	 */
	public BallRunnable(Ball aBall, Component aComponent)
	{
		this.ball = aBall;
		this.component = aComponent;
	}

	public void run()
	{
		try
		{
			for (int i = 1; i <= BallRunnable.STEPS; i++)
			{
				this.ball.move(this.component.getBounds());
				this.component.repaint();
				Thread.sleep(BallRunnable.DELAY);
			}
		}
		catch (InterruptedException e)
		{
		}
	}
}
